/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    height: 100vh;
    overflow: hidden;
}

/* Container styles - responsive height */
.container {
    width: 100%;
    height: 100vh;
    display: grid;
    grid-template-columns: 300px 1fr 280px;
    grid-template-rows: 1fr auto;
    gap: 10px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
}

/* Iframe detection and height adjustment */
@media (max-height: 500px) {
    .container {
        height: 450px;
        grid-template-rows: 1fr 60px;
    }
}

/* Control Panel Styles */
.control-panel {
    background: white;
    border-radius: 12px;
    padding: 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-group label {
    font-weight: 600;
    color: #333;
    font-size: 14px;
}

.control-group input[type="range"] {
    width: 100%;
    height: 8px;
    border-radius: 4px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
    cursor: pointer;
    transition: all 0.3s ease;
}

.control-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #4CAF50;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
}

.control-group input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.4);
}

.control-group span {
    font-weight: bold;
    color: #2196F3;
    text-align: center;
    padding: 4px 8px;
    background: #f0f8ff;
    border-radius: 4px;
    border: 1px solid #2196F3;
}

.button-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
}

.control-btn {
    padding: 12px 16px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 14px;
    min-height: 44px; /* Touch-friendly height */
}

.control-btn.start {
    background: #4CAF50;
    color: white;
}

.control-btn.start:hover:not(:disabled) {
    background: #45a049;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.3);
}

.control-btn.stop {
    background: #f44336;
    color: white;
}

.control-btn.stop:hover:not(:disabled) {
    background: #da190b;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(244, 67, 54, 0.3);
}

.control-btn.reset {
    background: #ff9800;
    color: white;
}

.control-btn.reset:hover {
    background: #e68900;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 152, 0, 0.3);
}

.control-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Apparatus Section Styles */
.apparatus-section {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.electrolysis-cell {
    position: relative;
    display: flex;
    align-items: flex-end;
    gap: 20px;
}

.water-container {
    width: 200px;
    height: 150px;
    background: linear-gradient(to bottom, #87CEEB 0%, #4682B4 100%);
    border: 3px solid #333;
    border-radius: 8px;
    position: relative;
    overflow: hidden;
}

.water-level {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to bottom, rgba(135, 206, 235, 0.8) 0%, rgba(70, 130, 180, 0.9) 100%);
    transition: height 0.5s ease;
    height: 80%;
}

.electrode {
    position: absolute;
    width: 8px;
    height: 120px;
    background: #666;
    border-radius: 4px;
    top: 15px;
}

.electrode.cathode {
    left: 40px;
    background: linear-gradient(to bottom, #666 0%, #333 100%);
}

.electrode.anode {
    right: 40px;
    background: linear-gradient(to bottom, #666 0%, #333 100%);
}

.gas-tubes {
    display: flex;
    gap: 15px;
}

.gas-tube {
    width: 60px;
    height: 180px;
    background: rgba(255, 255, 255, 0.9);
    border: 2px solid #333;
    border-radius: 8px;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px;
}

.gas-collection {
    position: absolute;
    bottom: 8px;
    left: 8px;
    right: 8px;
    border-radius: 4px;
    transition: height 0.5s ease;
    height: 0;
}

.hydrogen-tube .gas-collection {
    background: linear-gradient(to top, rgba(255, 192, 203, 0.7) 0%, rgba(255, 182, 193, 0.9) 100%);
}

.oxygen-tube .gas-collection {
    background: linear-gradient(to top, rgba(173, 216, 230, 0.7) 0%, rgba(135, 206, 235, 0.9) 100%);
}

.gas-tube label {
    font-weight: bold;
    font-size: 12px;
    color: #333;
    margin-top: 5px;
}

.gas-volume {
    font-size: 11px;
    color: #666;
    margin-top: auto;
    margin-bottom: 5px;
}

/* Circuit Section */
.circuit-section {
    display: flex;
    align-items: center;
    gap: 15px;
    position: relative;
}

.battery {
    width: 40px;
    height: 25px;
    background: linear-gradient(to right, #333 0%, #333 40%, #666 40%, #666 60%, #333 60%, #333 100%);
    border-radius: 4px;
    position: relative;
}

.battery::before {
    content: '+';
    position: absolute;
    right: -15px;
    top: 50%;
    transform: translateY(-50%);
    color: #d32f2f;
    font-weight: bold;
}

.battery::after {
    content: '-';
    position: absolute;
    left: -15px;
    top: 50%;
    transform: translateY(-50%);
    color: #1976d2;
    font-weight: bold;
}

.wire {
    height: 3px;
    width: 60px;
    background: #333;
    border-radius: 2px;
}

.current-indicator {
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 12px;
    color: #4CAF50;
    font-weight: bold;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.current-indicator.active {
    opacity: 1;
}

/* Data Section Styles */
.data-section {
    background: white;
    border-radius: 12px;
    padding: 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.data-panel h3 {
    color: #333;
    font-size: 16px;
    margin-bottom: 10px;
    text-align: center;
}

.data-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #eee;
    font-size: 14px;
}

.data-row span:first-child {
    font-weight: 600;
    color: #555;
}

.data-row span:last-child {
    font-weight: bold;
    color: #2196F3;
}

.graph-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#gas-chart {
    border: 1px solid #ddd;
    border-radius: 8px;
    background: white;
    max-width: 100%;
    height: auto;
}

.graph-legend {
    display: flex;
    gap: 15px;
    margin-top: 10px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 2px;
}

.legend-color.hydrogen {
    background: #ff6b6b;
}

.legend-color.oxygen {
    background: #4ecdc4;
}

/* Status Message */
.status-message {
    grid-column: 1 / -1;
    background: rgba(33, 150, 243, 0.1);
    border: 1px solid #2196F3;
    border-radius: 8px;
    padding: 12px;
    text-align: center;
    color: #1976D2;
    font-weight: 500;
    font-size: 14px;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .container {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto auto;
        gap: 8px;
        padding: 8px;
    }
    
    .control-panel {
        order: 1;
    }
    
    .apparatus-section {
        order: 2;
        padding: 15px;
    }
    
    .data-section {
        order: 3;
    }
    
    .status-message {
        order: 4;
    }
    
    .electrolysis-cell {
        flex-direction: column;
        align-items: center;
        gap: 15px;
    }
    
    .water-container {
        width: 150px;
        height: 120px;
    }
    
    .gas-tubes {
        flex-direction: row;
        justify-content: center;
    }
    
    .gas-tube {
        height: 120px;
        width: 50px;
    }
}

/* Animation for bubbles effect */
@keyframes bubble {
    0% { transform: translateY(0) scale(0.5); opacity: 0.7; }
    50% { transform: translateY(-20px) scale(1); opacity: 1; }
    100% { transform: translateY(-40px) scale(0.3); opacity: 0; }
}

.bubble {
    position: absolute;
    width: 4px;
    height: 4px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    animation: bubble 2s infinite;
    pointer-events: none;
}